﻿using HDFSViewer.Component;
using HDFSViewer.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using WpfAnimatedGif;

namespace HDFSViewer.Model
{
    public class OperationLogModel : NotifyObject
    {
        public const string Result_Processing = "Processing...";
        public const string Result_OK = "OK";
        public const string Result_Failed = "Failed";

        public string Type { get; set; }

        public OperationLogModel(string type, string info)
        {
            Type = type;
            _info = info;
        }

        private string _status = null;
        public string Status
        {
            get { return _status; }
            set
            {
                _status = value;
                this.RaisePropertyChanged("Status");
            }
        }

        public string Message
        {
            get { return string.Concat(_info, " ", _result); }
        }

        private string _info = null;
        public string Info
        {
            get { return _info; }
            set
            {
                _info = value;
                this.RaisePropertyChanged("Info");
                this.RaisePropertyChanged("Message");
            }
        }

        private string _result = null;
        public string Result
        {
            get { return _result; }
            set
            {
                _result = value;
                this.RaisePropertyChanged("Result");
                this.RaisePropertyChanged("Message");
            }
        }

        public void ChangeStatus(LogStatus status)
        {
            if (status == LogStatus.Loading)
            {
                Status = @"\View\GIF\Loading.gif";
            }
            else if (status == LogStatus.Success)
            {
                Status = @"\View\SmallImage\Success.png";
            }
            else if (status == LogStatus.Failed)
            {
                Status = @"\View\SmallImage\Failed.png";
            }
        }

        public void ChangeStatus(LogStatus status, string result)
        {
            ChangeStatus(status);
            Result = result;
        }

        public void ChangeStatusWithDispatcherInvoke(LogStatus status, string result)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                ChangeStatus(status);
                Result = result;
            });
        }
    }
}